package com.atguigu.synac;
class Ticket{
    private Integer ticket = 300;
    public synchronized void sale(){
        if(ticket<=0){
            System.out.println("票卖完了");
            return;
        }
        System.out.println(Thread.currentThread().getName()+"卖出了第"+(ticket--)+"张票，剩余："+ticket);
    }
}

public class SaleTicket {
    public static void main(String[] args) {
        Ticket ticket = new Ticket();
        new Thread(() -> {
            for(int i = 0; i < 100; i++){
                ticket.sale();
            }
        },"A").start();
        new Thread(() -> {
            for(int i = 0; i < 100; i++){
                ticket.sale();
            }
        },"B").start();
        new Thread(() -> {
            for(int i = 0; i < 100; i++){
                ticket.sale();
            }
        },"C").start();
    }
}
